package com.jerome.election.enums;

import java.util.HashMap;
import java.util.Map;

/**
 * java class enumeration
 *
 * @author: Jerome
 * @date :  2020-06-17 14:45
 * @version V1.0
 */
public enum ClassEnum {
    /**
     * java.lang.String
     */
    String("java.lang.String",String.class),
    /**
     * java.lang.Character
     */
    Character("java.lang.Character",Character.class),
    /**
     * java.lang.Byte
     */
    Byte("java.lang.Byte",Byte.class),
    /**
     * java.lang.Short
     */
    Short("java.lang.Short",Short.class),
    /**
     * java.lang.Integer
     */
    Integer("java.lang.Integer",Integer.class),
    /**
     * java.lang.Long
     */
    Long("java.lang.Long",Long.class),
    /**
     * java.lang.Float
     */
    Float("java.lang.Float",Float.class),
    /**
     * java.lang.Double
     */
    Double("java.lang.Double",Double.class),
    /**
     * java.lang.Double
     */
    BigDecimal("java.math.BigDecimal", java.math.BigDecimal.class),
    /**
     * java.lang.Boolean
     */
    Boolean("java.lang.Boolean",Boolean.class),
    /**
     * java.util.Date
     */
    Date("java.util.Date", java.util.Date.class),
    /**
     * java.lang.Object
     */
    Object("java.lang.Object",Object.class),
    /**
     * java.util.List
     */
    List("java.util.List", java.util.List.class),
    /**
     * java.util.Map
     */
    Map("java.util.List", java.util.Map.class),

    //基础类型
    SHORT("short",short.class),
    BYTE("byte",byte.class),
    INT("int",int.class),
    LONG("long",long.class),
    FLOAT("float",float.class),
    DOUBLE("double",double.class),
    CHAR("char",char.class),
    BOOLEAN("boolean",boolean.class),
    SHORT_ARR("short[]",short[].class),
    INT_ARR("int[]",int[].class),
    LONG_ARR("long[]",long[].class),
    FLOAT_ARR("float[]",float[].class),
    DOUBLE_ARR("double[]",double[].class),
    CHAR_ARR("char[]",char[].class),
    BOOLEAN_ARR("boolean[]",boolean[].class);
    private static Map<Class,ClassEnum> map =new HashMap();
    private static Map<String,ClassEnum> classMap =new HashMap();
    static {
        for (ClassEnum value : ClassEnum.values()) {
            map.put(value.getClazz(),value);
            classMap.put(value.className,value);
        }
    }

    /**
     * 根据类获取到类枚举
     * @param clazz
     * @return ClassEnum
     */
    public static ClassEnum getByClazz(Class clazz){
        return map.get(clazz);
    }

    /**
     * 根据类逻辑名获取类枚举
     * @param className
     * @return ClassEnum
     */
    public static ClassEnum getByClassName(String className){
        return classMap.get(className);
    }
    /**
     * 根据类逻辑名获取类枚举
     * @param className
     * @return ClassEnum
     */
    public static Class getClassByClassName(String className){
        ClassEnum classEnum = classMap.get(className);
        if(classEnum!=null){
            return classEnum.getClazz();
        }
        return null;
    }
    private String className;
    private Class clazz;

    ClassEnum(java.lang.String className, Class clazz) {
        this.className = className;
        this.clazz = clazz;
    }

    public java.lang.String getClassName() {
        return className;
    }

    public void setClassName(java.lang.String className) {
        this.className = className;
    }

    public Class getClazz() {
        return clazz;
    }

    public void setClazz(Class clazz) {
        this.clazz = clazz;
    }
}
